<?php


namespace App\Utils;

use OSS\OssClient;
use OSS\Core\OssException;

class AliOssClient
{
    static function uploadFile($filePath, $object)
    {
        $accessKeyId = config('ali_oss.access_id');
        $accessKeySecret = config('ali_oss.access_key');
        $endpoint = "http://oss-cn-shanghai.aliyuncs.com";
        $bucket = config('ali_oss.bucket');
        try {
            $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
            $ossClient->uploadFile($bucket, $object, $filePath);
        } catch (OssException $e) {
            printf(__FUNCTION__ . ": FAILED\n");
            printf($e->getMessage() . "\n");
            return;
        }
    }
}